const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const fs = require('fs');
const path = require("path");

module.exports = {
  configureWebpack:{
    resolve:{
      alias:{
        'assets':'@/assets',
        'css':'assets/css',
        'images':'assets/images',
        'components':'@/components',
        'networks':'@/networks',
        'utils':'@/utils',
        'views':'@/views',
        'store':'@/store',
      }
    },
    devtool: 'source-map', // 配置本地调试, 去掉此配置,加载时间会变慢
    module: {
      rules: [
        {
          test: /\.mjs$/,
          include: /node_modules/,
          type: "javascript/auto"
        },
      ]
    },
    plugins: [
      //手动导入配置
      // require('unplugin-element-plus/webpack')({
      //   // options
      // }),
      //自动导入element-plus组件
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
  },
  css:{
    loaderOptions:{
      sass:{
        additionalData:`
                   @import "@/assets/scss/variables.scss";
               @import "@/assets/scss/mixin.scss";
               `
      }
    }
  },
  publicPath: process.env.NODE_ENV === 'production' ?  '/34fwind/' : '/34fwind/',
  outputDir:'34fwind',
  devServer: {
    proxy: {
      '/api': {
        // target: 'https://iloveyezi.life/svyServer/',
        target: 'http://localhost:9090/svyServer/',
        // 允许跨域
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/api': ''
        }
      },
      // '/grap': {
      //   // target: 'http://localhost:9090/svyCrawlServer/',
      //   target: 'https://iloveyezi.cn/svyCrawlServer/',
      //   // 允许跨域
      //   changeOrigin: true,
      //   ws: true,
      //   pathRewrite: {
      //     '^/grap': ''
      //   }
      // }
    },
    // port:8080,
    //启动压缩, 节省加载时间,
    //启动https时, 文件加载时间从2.3min->19.85sec
    //http时 文件加载时间 1.8min->18.77sec
    compress: true,
    //此处开启https, 在二维码扫码时需要使用https, 否则平板不能启动摄像头
    // https:true,
  }
}